<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
      <panel-group :devops="devops" />
      <el-row :gutter="40"  class="panel-group">
        <el-col :span="24" class="card-box">
          <el-card>
            <div slot="header">
              <span>服务器信息</span>
            </div>
            <div class="el-table el-table--enable-row-hover el-table--medium">
              <table cellspacing="0" style="width: 100%;">
                <tbody>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">服务器名称</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.sys">{{ server.sys.computerName }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">操作系统</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.sys">{{ server.sys.osName }}</div>
                    </td>
                  </tr>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">服务器IP</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.sys">{{ server.sys.computerIp }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">系统架构</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.sys">{{ server.sys.osArch }}</div>
                    </td>
                  </tr>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">CPU核心数</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.cpu">{{ server.cpu.cpuNum }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">CPU空闲率</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.sys" :class="{'text-danger': server.cpu.free  < 20}">
                        {{ server.cpu.free }}%
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">总内存</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.mem">{{ server.mem.total }}G</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">内存使用率</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.mem" :class="{'text-danger': server.mem.usage > 80}">
                        {{ server.mem.usage }}%
                      </div>
                    </td>
                  </tr>

                </tbody>
              </table>
            </div>
          </el-card>
        </el-col>

        <el-col :span="24" class="card-box">
          <el-card>
            <div slot="header">
              <span>Java虚拟机信息</span>
            </div>
            <div class="el-table el-table--enable-row-hover el-table--medium">
              <table cellspacing="0" style="width: 100%;">
                <tbody>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">Java名称</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.jvm">{{ server.jvm.name }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">Java版本</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.jvm">{{ server.jvm.version }}</div>
                    </td>
                  </tr>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">启动时间</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.jvm">{{ server.jvm.startTime }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">运行时长</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.jvm">{{ server.jvm.runTime }}</div>
                    </td>
                  </tr>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">JVM内存</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.jvm">{{ server.jvm.total }}M</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">内存使用率</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" v-if="server.jvm" :class="{'text-danger': server.jvm.usage > 80}">
                        {{ server.jvm.usage }}%
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">运行程序</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ appName }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">程序版本</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ appVersion }}</div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </el-card>
        </el-col>

        <el-col :span="24" class="card-box">
          <el-card>
            <div slot="header">
              <span>磁盘状态</span>
            </div>
            <div class="el-table el-table--enable-row-hover el-table--medium">
              <table cellspacing="0" style="width: 100%;">
                <thead>
                  <tr>
                    <th class="el-table__cell el-table__cell is-leaf">
                      <div class="cell">盘符路径</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">文件系统</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">盘符类型</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">总大小</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">可用大小</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">已用大小</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">已用百分比</div>
                    </th>
                  </tr>
                </thead>
                <tbody v-if="server.sysFiles">
                  <tr v-for="(sysFile, index) in server.sysFiles" :key="index">
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ sysFile.dirName }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ sysFile.sysTypeName }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ sysFile.typeName }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ sysFile.total }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ sysFile.free }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">{{ sysFile.used }}</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell" :class="{'text-danger': sysFile.usage > 80}">{{ sysFile.usage }}%</div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>

</template>

<script>
  import {
    getDashboard
  } from "@/api/devops/dashboard";
  import PanelGroup from './dashboard/PanelGroup'
  export default {
    name: "Dashboard",
    components: {
      PanelGroup,
    },
    data() {
      return {
        // 服务器信息
        server: [],
        devops: { totalHosts: 0, todayCollects: 0, totalAlarms: 0, untreatedAlarms: 0,todayAlarms: 0 },
        appName: "网络安全运维用信息系统",
        appVersion: "1.0.0"
      };
    },
    created() {
      this.getList();
      this.openLoading();
    },
    methods: {
      /** 查询服务器信息 */
      getList() {
        getDashboard().then(response => {
          this.devops = response.data.devops;
          this.server = response.data;
          this.$modal.closeLoading();
        });
      },
      // 打开加载层
      openLoading() {
        this.$modal.loading("正在加载服务器数据，请稍候！");
      }
    }
  };
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .dashboard-editor-container {
    padding: 18px 22px 22px 22px;
    background-color: rgb(240, 242, 245);

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }
</style>
